<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>出差申请表</title>
    <script src="../static/js/jquery-3.2.1.min.js"></script>
    <script src="../static/js/vue.js"></script>
    <link href="//unpkg.com/layui@2.8.0/dist/css/layui.css" rel="stylesheet">
    <!-- 引入 layui.js -->
    <script src="//unpkg.com/layui@2.8.0/dist/layui.js"></script>
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="../static/js/Core_values.js"></script>

    <style>
        #app{
            width: 500px;
            height: 300px;
            border:2px cornflowerblue solid;
            margin-left: 400px;
            margin-top: 150px;
        }
    </style>

</head>
<body>
<script src="../static/js/flower.js"></script>

<div id="app">
    <h3 style="text-align: center;height: 40px;background: cornflowerblue">出差申请提交表</h3>
    <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="出差天数">
            <el-input v-model="form.tripDays"></el-input>
        </el-form-item>
        <el-form-item label="出差日期">
            <el-col :span="11">
                <el-date-picker type="date" placeholder="选择日期" v-model="form.tripDate" style="width: 100%;"></el-date-picker>
            </el-col>
        </el-form-item>
        <el-form-item label="出差地">
            <el-input type="text" v-model="form.tripPlace"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="apply">立即创建</el-button>
            <el-button>取消</el-button>
        </el-form-item>
    </el-form>
</div>

<script>
    new Vue({
        el:"#app",
        data:{
            form:{
                userName:JSON.parse(localStorage.getItem("userName")),
                tripDays:"",
                tripPlace:"",
                tripDate:""
            }
        },
        methods:{
            apply(){
                var v=this
                v.$confirm("是否执行此操作?","确认提交",{
                    confirmButtonText: '确定',
                    cancelButtonText: '我再想想',
                    type: 'warning'
                }).then(() => {
                    $.ajax({
                        url:"../trip/apply",
                        type:"post",
                        contentType:"application/json",
                        data:JSON.stringify(v.form),
                        success:function (res) {
                            if(res.status===200){
                                v.$message.success("申请已提交")
                            }
                        },
                        error:function () {
                            v.$message.error("服务器出错")
                        }
                    })
                })
            }
        }
    })

</script>
</body>
</html>
